/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sunsite.action;

import com.opensymphony.xwork2.ActionSupport;
import java.util.Locale;
import org.springframework.context.support.ResourceBundleMessageSource;
import sunsite.service.UserService;
import sunsite.tools.Json;

/**
 *
 * @author Ruby
 */
public class DeleteUser extends ActionSupport {
    private UserService userService;
    private ResourceBundleMessageSource messageSource;
    public static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(DeleteUser.class);
    
    private String userName;
    
    private String message;
    
    @Override
    public String execute() throws Exception 
    {
        try
        {
            userService.delete(userName);
            Json json = new Json();
            json.add(Json.Answer, Json.Informantion);
            json.add(Json.MsgTitle, messageSource.getMessage("message.defaultMsgTitle", null, Locale.getDefault()));
            json.add(Json.MsgContent, messageSource.getMessage("user.delSuccess", null, Locale.getDefault()));
            message = json.toString();
        }
        catch(Exception err)
        {
            logger.error(err);
            Json json = new Json();
            json.add(Json.Answer, Json.ModalMessageBox);
            json.add(Json.MsgTitle, messageSource.getMessage("message.errorMsgTitle", null, Locale.getDefault()));
            json.add(Json.MsgContent, messageSource.getMessage("user.delFail", null, Locale.getDefault())+" : "+err.toString());
            message = json.toString();
        }
        return SUCCESS;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getMessage() {
        return message;
    }

    public void setMessageSource(ResourceBundleMessageSource messageSource) {
        this.messageSource = messageSource;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
}
